package javademo;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;

/**
 * 项目名称:spark-learn<br>
 * 包名:javademo<br>
 * 用于:spark-learn<br>
 * 创建时间:2019年03月15日<br>
 * 更新时间:2019年03月15日<br>
 *
 * @author :lds（创建人）<br>
 * @version :v1.0（版本号）<br>
 * @since jdk1.8
 */
public class ParallelizeDemo {

    public static void main(String[] args) {
        final JavaSparkContext sparkContext = SparkContextFactory.getContext("parallelize");
        final JavaRDD<Integer> parallelizeRDD = sparkContext.parallelize(Arrays.asList(1,2,3,4));

        //求均值
        final Double mean = parallelizeRDD.mapToDouble(x -> x * x).mean();
        System.out.println(mean);

        //aggregate
        final JavaRDD<Integer> z = sparkContext.parallelize(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8), 2);
        final Integer aggregate = z.aggregate(0, Math::max, (x, y) -> x + y);
        System.out.println("aggregate:"+aggregate);

        //



    }
}
